//
//  MyBidJobDetailTabChecklist.swift
//  ezyform
//
//  Created by MoennigQ on 12/12/18.
//  Copyright © 2018 Client.Solution Pty Ltd. All rights reserved.
//

import UIKit
import SnapKit
import RxSwift
import RxCocoa
class ServiceDetailTabChecklist: View {
    private lazy var disposeBag = DisposeBag()
    let tableView = ServcieChecklistTableView()
    let supportFunctionView = ServiceDetailSupportFunctionView()
    var checklistTableViewHeightConstant: Constraint?
    
    override func setUpView() {
        self.backgroundColor = UIColor(hexStr: Constant.SystemBackColor)
        let scrollView = DIYScrollView()
        scrollView.backgroundColor = .clear
        self.addSubview(scrollView)
        scrollView.snp.makeConstraints { (make) in
            make.edges.equalTo(self)
        }
        let contentView = UIView()
        contentView.backgroundColor = .clear
        scrollView.addSubview(contentView)
        contentView.snp.makeConstraints { (make) in
            make.top.bottom.equalTo(scrollView)
            make.left.right.equalTo(self)
            make.height.greaterThanOrEqualTo(0)
        }
        //table view
        contentView.addSubview(tableView)
        tableView.snp.makeConstraints { (make) in
            make.top.equalToSuperview()
            make.left.right.equalToSuperview()
            self.checklistTableViewHeightConstant = make.height.greaterThanOrEqualTo(0).constraint
        }
        //suppor function
        let supportFuncLabel = ContentLabel(R.font.interRegular(size: 12),hexStr: "#292D3299")
        supportFuncLabel.text = "SUPPORT FUNCTIONS"
        contentView.addSubview(supportFuncLabel)
        supportFuncLabel.snp.makeConstraints { make in
            make.top.equalTo(tableView.snp.bottom).offset(20)
            make.left.equalTo(24)
            make.width.height.greaterThanOrEqualTo(0)
        }
        contentView.addSubview(supportFunctionView)
        supportFunctionView.snp.makeConstraints { make in
            make.top.equalTo(supportFuncLabel.snp.bottom).offset(9)
            make.left.equalTo(12)
            make.right.equalTo(-12)
            make.height.greaterThanOrEqualTo(0)
            make.bottom.equalTo(-20)
        }
        //绑定checklisttableview的g
        tableView.rx.observe(CGSize.self,"contentSize").subscribe {[weak self] (size) in
            guard let contentSize = size else {return}
            self?.checklistTableViewHeightConstant?.update(offset: contentSize.height)
        }.disposed(by: self.disposeBag)
    }
}
